package lion.framework.core.web.anno;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

import lion.dev.lang.MapJ;
import lion.framework.core.anno.AnnotationProcessorManager;
import lion.framework.core.anno.IAnnotationProcessor;
import lion.framework.core.web.path.PathNode;
import lion.framework.core.web.views.ResultType;

/**
 * 视图注解处理类
 * 
 * @author lion
 * @email hl_0074@sina.com
 * @date 2015年3月18日
 */
public class ViewProcessor implements IAnnotationProcessor {

	@Override
	public void processe(MapJ ctx, Annotation anno) {

		PathNode pathNode = ctx.getE(PathMappingProcessor.PATH_NODE);
		Method method = ctx.getE(AnnotationProcessorManager.ANNO_CONTEXT_TARGET);
		if (pathNode == null) { return; }
		if (anno == null || method.getReturnType().equals(Void.TYPE)) {
			pathNode.addView("success", "", ResultType.NOOP);
			return;
		}
		Result result = (Result) anno;
		View[] views = result.value();

		if (views == null || views.length == 0) {
			pathNode.addView("success", "", ResultType.NOOP);
			return;
		}

		for (View v : views) {
			pathNode.addView(v.name(), v.value(), v.type());
		}
	}
}
